﻿activateImg = function () {
    document.getElementById("partImageFile").click();
}
function S4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
function guid() {
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}
fnUploadImg = function () {
    var imgCtrl = document.getElementById("partImageFile");
    var form = imgCtrl.form;
    var oldAction = form.action;
    var oldTarget = form.target;
    var oldMethod = form.method;
    var imgCode = guid();
    var oldTxtAction = document.getElementById("MainContent_txtAction").value;
    form.method = "POST";
    form.target = "imgIfr";
    form.enctype = "multipart/form-data";
    document.getElementById("MainContent_txtImgCode").value = imgCode;
    document.getElementById("MainContent_txtAction").value = "UploadImage";
    form.submit();
    form.action = oldAction;
    form.method = oldMethod;
    form.target = oldTarget;
    document.getElementById("MainContent_txtAction").value = oldTxtAction;
}
fnHdlJQSearch = function (control) {
    document.getElementById(control).value = "0";
}
fnHdlJQResult = function (control, item) {
    document.getElementById(control).value = item[1];
}
fnHdlJQParse = function (control, data) {
    if (!data || data.length == 0) {
        fnHdlJQSearch(control);
    }
}

refreshImg = function (image) {
    document.getElementById("partImg").src = "Image.aspx?PK=0&img=" + image;
    document.getElementById("MainContent_txtImgCode").value = image;
}
validateInput = function () {
    var controls = document.getElementsByTagName("input");
    var valid = true;
    for (var i = 0; i < controls.length; i++) {
        var thisControl = controls[i];
        if (thisControl.getAttribute("disabled") != "disabled") {
            var validation = thisControl.getAttribute("billdervalidation");
            if (validation) {
                if (validation == "notEmpty" && thisControl.value == "") {
                    var oldClass = thisControl.getAttribute("class");
                    thisControl.setAttribute("class", oldClass + " invalid");
                    valid = false;
                }
                if (validation == "float" && (isNaN(thisControl.value) || thisControl.value == "")) {
                    var oldClass = thisControl.getAttribute("class");
                    thisControl.setAttribute("class", oldClass + " invalid");
                    valid = false;
                }
            }
        }
    }
    if (!valid) {
        alert("Existen datos invalidos, por favor corrija los campos marcados con rojo");
    }
    return valid;
}
